package com.itheima.boottlias.controller;

import com.itheima.boottlias.domain.dto.LoginDTO;
import com.itheima.boottlias.domain.vo.LoginVO;
import com.itheima.boottlias.domain.vo.Result;
import com.itheima.boottlias.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ghy
 * @version 1.0
 * @since 2025-07-17 08:42
 */
@RestController
@Slf4j
public class LoginController {

    @Autowired
    private EmpService empService;

    @PostMapping("/login")
    public Result login(@RequestBody LoginDTO loginDTO){
        log.info("{}", loginDTO);
        LoginVO loginVO = empService.login(loginDTO);
        if(loginVO.getId() == null) {
            return Result.error(loginVO.getMessage());
        }
        return Result.success(loginVO);
    }

}
